﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using XuanXiang.Infrastructure.Attr;
using XuanXiang.Infrastructure.Dto.Request;
using XuanXiang.Infrastructure.Dto.Request.Supplier;
using XuanXiang.Service.Interface;

namespace XuanXiang.Api.Admin.Controllers
{

    [ApiGroup("Admin(管理员模块)")]
    public class SupplierController : BaseController
    {
        private readonly I_Supplier_Service _supplier_Service;

        public SupplierController(I_Login_Service login_Service, I_Supplier_Service supplier_Service) : base(login_Service)
        {
            _supplier_Service = supplier_Service;
        }


        /// <summary>
        /// 获取供应商
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_Supplier(int page = 1, int limit = 10, string? key = "")
        {
            var result = await _supplier_Service.Get_Supplier(new Fenye_Dto()
            {
                page = page,
                limit = limit,
                key = key ?? ""
            });
            return Ok(result);
        }

        /// <summary>
        /// 供应商的禁用/启用
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> IsBan_Supplier(IsBan_Dto dto)
        {
            var result = await _supplier_Service.IsBan_Supplier(dto);
            return Ok(result);
        }

        /// <summary>
        /// 供应商的删除
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Delete_Supplier(Delete_Dto dto) {
            var result = await _supplier_Service.Delete_Supplier(dto.id);
            return Ok(result);
        }

        /// <summary>
        /// 供应商新增
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Add_Supplier(Supplier_Add_Dto dto) {
            var result = await _supplier_Service.Add_Supplier(dto);
            return Ok(result);
        }


        /// <summary>
        /// 获取单个供应商
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_Single_Supplier(string? id)
        {
            var result = await _supplier_Service.Get_Single_Supplier(id);
            return Ok(result);
        }

        /// <summary>
        /// 获取供应商的畅销商品/订单
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_Supplier_Orders(string? id, int page = 1, int limit = 10)
        {
            var result = await _supplier_Service.Get_Supplier_Orders(new Fenye_Dto()
            {
                page = page,
                limit = limit,
                id = id
            });
            return Ok(result);
        }

        /// <summary>
        /// 获取供应商的数据/商品
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_Supplier_Goods(string? id, int page = 1, int limit = 10)
        {
            var result = await _supplier_Service.Get_Supplier_Goods(new Fenye_Dto()
            {
                page = page,
                limit = limit,
                id = id
            });
            return Ok(result);
        }

        /*/// <summary>
        /// 获取供应商的经营种类
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_Supplier_Type(string? id)
        {
            var result = await _supplier_Service.Get_Supplier_Type(id);
            return Ok(result);
        }*/
    }
}
